'''
Created on Feb 10, 2010

@author: christianp
'''

class ZoomHelper(object):
    '''
    classdocs
    '''

    def __init__(self):
        '''
        Constructor
        '''
    
    @staticmethod
    def zoomIn(resolutions, resolution):
        if(resolutions[len(resolutions)-1][1] > resolution):
            return resolutions[len(resolutions)-1][1]
        
        for i in range(0, len(resolutions)):
            if(resolutions[i][1] < resolution):
                return resolutions[i][1]
        
        return resolutions[len(resolutions)-1][1]
    
    @staticmethod
    def findZoomLevelsBetween(end_level, begin_level, resolutions):
        zoom_levels = []
        for resolution in resolutions:
            resolution = resolution[1]
            if(resolution <= end_level):
                if(resolution >= begin_level):
                    zoom_levels.append(resolution)
        
        return zoom_levels
    
    @staticmethod
    def findNearestResolution(resolutions, resolution):
        for i in range(0, len(resolutions)):
            small_resolution = min(resolutions[i][1], resolution)
            if not(small_resolution == resolution):
                return resolutions[i][1]
        
        return resolutions[len(resolutions) - 1][1]
    
    @staticmethod
    def zoomToBoudingBox(self, extent, screen_width, resolution):    
        resolution = (extent.getMaxX() - extent.getMinX()) / screen_width
        return resolution
    
    @staticmethod
    def zoomOut(resolutions, resolution):
        if(resolutions[0] < resolution):
            return resolutions[0]
        
        for i in range((len(resolutions)-1), 0, -1):
            if(resolutions[i][1] > resolution):
                return resolutions[i][1]
        
        return resolutions[0][1]